package cn.u313.listener;

import cn.u313.comm.utils.Util;
import cn.u313.model.MsgInfo;
import cn.u313.service.BlessingEntryService;
import love.forte.common.ioc.annotation.Beans;
import love.forte.common.ioc.annotation.Depend;
import love.forte.simbot.annotation.Filter;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.sender.MsgSender;
import love.forte.simbot.bot.Bot;
import love.forte.simbot.bot.BotManager;
import love.forte.simbot.bot.PairBotVerifyInfo;
import love.forte.simbot.filter.MatchType;
import me.kuku.pojo.Result;
import me.kuku.test.QQlogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

//@Beans
//@Component
public class BlessingListtener  extends BaseListen{
//
@Autowired
    private BotManager botManager;
    @Autowired
    BlessingEntryService blessingEntryService;
    int bleMemory=20;
    int ciShu=1;

    @OnGroup
    @Filter(value = "抽福卡", matchType = MatchType.STARTS_WITH)
//    @Filter(value = "兔", matchType = MatchType.STARTS_WITH)
//    @Filter(value = "抽兔卡", matchType = MatchType.STARTS_WITH)
    public void getBlessing(GroupMsg groupMsg, MsgSender msgSender) {
        if(Util.is8点()){
            sendMsg(msgSender,groupMsg,"已经不能抽福卡了哦，现在发送关键字：瓜分大奖 参与活动！");
            return;
        }
        String qq = getQQ(groupMsg);
        String group = getGroup(groupMsg);
        String msgs = blessingEntryService.addCard(group,qq);
        sendMsg(msgSender,groupMsg,msgs);


    }

    @OnGroup
    @Filter(value = "福卡活动|菜单|活动"  ,matchType = MatchType.REGEX_MATCHES)
    public  void wds(GroupMsg groupMsg, MsgSender msgSender) {

        msgSender.SENDER.sendGroupMsg(groupMsg,"福卡活动介绍：\n" +
                "活动时间：1.12-1.30\n" +
                "关键字: \n【抽福卡】\n【抽红包】\n【转赠】\n【万能卡兑换】\n【我的福卡】\n【福卡详情】\n每次抽福卡和抽红包将消耗 20 悦币哦" +
                "\n大年三十晚八点群里瓜分大量悦币和红包（可提现）\n---------------------\n活动一切解释权归灵悦所有,禁止恶意使用bug,小号恶意刷取活动资源等扰乱活动秩序的行为");
    }




    @OnGroup
    @Filter(value = "test003"  ,matchType = MatchType.STARTS_WITH)
    public  void loginVf(GroupMsg groupMsg, MsgSender msgSender) {
        String s = getCode(groupMsg);
        String[] ss= s.split(":");
        if (ss == null) {

            sendMsg(msgSender,groupMsg,"无账号");
            return;
        }
        PairBotVerifyInfo.BasicBotVerifyInfo basicBotVerifyInfo = new PairBotVerifyInfo.BasicBotVerifyInfo(ss[0],ss[1]);
        Bot a = botManager.registerBot(basicBotVerifyInfo);

        System.out.println(a);
        System.out.println(a.getBotInfo());
        sendMsg(msgSender,groupMsg,"账号："+ss[0]+"\n"+a.getBotInfo());
    }

    @OnGroup
    @Filter(value = "福卡详情", matchType = MatchType.STARTS_WITH)
    @Filter(value = "我的福卡", matchType = MatchType.STARTS_WITH)
    public  void xq(GroupMsg groupMsg, MsgSender msgSender) {

        String qq = getQQ2(groupMsg);
        String msgs = blessingEntryService.select(qq);
        sendMsg(msgSender,groupMsg,msgs);

    }
    @OnGroup
    @Filter(value = "瓜分大奖", matchType = MatchType.STARTS_WITH)
    @Filter(value = "福卡开奖", matchType = MatchType.STARTS_WITH)
    @Filter(value = "大吉大利", matchType = MatchType.STARTS_WITH)
    @Filter(value = "开奖", matchType = MatchType.STARTS_WITH)
    @Filter(value = "给爷开", matchType = MatchType.STARTS_WITH)
    public  void wdss(GroupMsg groupMsg, MsgSender msgSender) {
        if (!Util.is8点())return;
        try {
            new Thread(() -> {
                Result<String> msg = null;
//                System.out.println("login>>>1");、、QQlogin.login()
                try {
                    String qq  = getQQ(groupMsg);
                    blessingEntryService.new30Thread(qq,new MsgInfo(groupMsg,msgSender));

                } catch (Exception e) {
                    sendMsg(msgSender,groupMsg,"异常 code ={"+e.getMessage()+"}");
                    e.printStackTrace();
                }

            }).start();

        } catch (Exception e) {
            e.printStackTrace();
        }



    }

    @OnGroup
    @Filter(value = "万能卡", matchType = MatchType.STARTS_WITH)
    public   void wd(GroupMsg groupMsg,MsgSender msgSender) {
        String qq= getQQ(groupMsg);
        String group= getGroup(groupMsg);
        String type = getCode(groupMsg);
        String msgs = blessingEntryService.duiHuan(qq,group,type);
        sendMsg(msgSender,groupMsg,msgs);

    }
    @OnGroup
    @Filter(value = "福卡赠送", matchType = MatchType.CONTAINS)
    @Filter(value = "转赠", matchType = MatchType.CONTAINS)
    public   void zs(GroupMsg groupMsg,MsgSender msgSender) {
        if(Util.is8点()){
        sendMsg(msgSender,groupMsg,"已经不能抽福卡了哦，现在发送关键字：瓜分大奖 参与活动！");
        return;
    }
        String qq= getQQ(groupMsg);
        String qq1= getAt(groupMsg);
        String group= getGroup(groupMsg);
        String type = getCode(groupMsg);
        String msgs = blessingEntryService.zengSong(qq,qq1,group,type);
        sendMsg(msgSender,groupMsg,msgs);

    }
    @OnGroup
    @Filter(value = "团团圆圆", matchType = MatchType.CONTAINS)
    @Filter(value = "团圆", matchType = MatchType.STARTS_WITH)
    @Filter(value = "领取万能卡", matchType = MatchType.STARTS_WITH)
    public  void wn(GroupMsg groupMsg,MsgSender msgSender) {
        String qq= getQQ(groupMsg);
        if(isManager(groupMsg)||Util.isChuXi()){

            sendMsg(msgSender,groupMsg,blessingEntryService.lingQuTuanYuanCard(qq,getGroup(groupMsg)),false);
        }else {

            sendMsg(msgSender,groupMsg,"除夕快乐鸭！",false);
        }


    }
}
